<template>
	<view style="background-color: #f1f1f1;height: 250vh;">
		<view class="formBox">
			<u--form :model="form" ref="uForm" :rules="rules">
				<view class="labelBox">
					<u-form-item label="描述:" labelWidth="100rpx" prop="ms" >
					</u-form-item>
					<u-input style="width: 200rpx;" placeholder="请对缺损情况进行适当的描述" v-model="form.ms" />
				</view>
				<!-- <view class="labelBox2">
					<u-form-item label="语音:" labelWidth="100rpx" prop="ly" >
						
					</u-form-item>
					<view class="djlyBox" >
						<text class="djlyBox-text">点击录音</text>
					</view>
					<u-input v-model="form.ly" />
				</view> -->
				<view class="labelBox3">
					<u-form-item label="拍照:" labelWidth="100rpx" prop="photo" >
						<view class="photoBox">
							<u-upload
									:fileList="fileList1"
									@afterRead="afterRead"
									@delete="deletePic"
									name="1"
									multiple
									:maxCount="10"
								></u-upload>
						</view>
					</u-form-item>
				</view>
				<!-- <u-input v-model="form.photo"> -->
			</u--form>
			<view class="btn">
				<u-button class="btn" type="primary" @click="qdbtn(form)">确定</u-button>	
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
						ms: '',
						ly: '',
						photo: '',
					},
				rules: {
					ms: [
						{
							required: true,
							message: '请输入',
							trigger: ['blur', 'change']
									}
							],
						// 	ly: [
						// {
						// 	required: true,
						// 	message: '请录音',
						// 	trigger: ['blur', 'change']
						// 			}
						// 	],
						// 	photo: [
						// {
						// 	required: true,
						// 	message: '请上传',
						// 	trigger: ['blur', 'change']
						// 			}
						// 	],
						},
						fileList1: [],
						bclyData:{},
						dh:''

			}
		},
		onLoad(query) {
			// console.log(query,'补充留言');
			// 从 query 中获取传递过来的数据，并将其转换为对象
			    this.bclyData = JSON.parse(query.dataList);
				console.log(this.bclyData,'补充留言跳转数据');
				this.dh = this.bclyData.YDRNUM
				// console.log(this.dh,'danhao');
		},
		methods: {
				qdbtn(q) {
					// console.log(q);
					// this.$refs.uForm.validate().then(res => {
					// 	uni.$u.toast('校验通过')
					// }).catch(errors => {
					// 	uni.$u.toast('校验失败')
					// })
					let GRP1 = {
						GRP1: [{
								YFLG: "3",//标识
								YDRNUM: this.dh,//单号
								REPCONT:q.ms
						}]
					}
					let GRP1Json = JSON.stringify(GRP1)
					console.log(GRP1Json,'55666667777888');
					uni.request({
					  url: 'http://125.64.76.148:8125/KXJDX3Api/x3api', // 替换为实际的接口URL
					  method: 'POST', 
					  data: {
						"username":"APIUSER",
						"passwd":"123",
						"publicName":"WSGENXDR",
						"method":"run",
						"test":uni.getStorageSync('test') ? "true" : "false",
						"inputXml":JSON.stringify(GRP1)
					  },
					  success: (res) => {
						  // console.log(res.data.message,'补充留言数据');
						// // 请求成功的处理逻辑
						if(res.data.status=="error"){
							alert(res.data.message);
							return false;
						}else{
							let wpdData = JSON.parse(res.data.message)
							// console.log(wpdData.GRP2,56777);
							if(wpdData.GRP1.WOK==0){
								// 显示创建成功的消息提示
								 uni.showToast({
								   title: '补充成功',
								   icon: 'success',
								   duration: 2000
								});
								this.form=''
								// 使用 uni.navigateTo 跳转到 my 页面，并传递数据
								 // uni.navigateTo({url:"/pages/zpslPages/zpslPages?wpdData="+JSON.stringify(wpdData)})
							}else{
								uni.showToast({
								   title: '补充失败',
								   icon: 'error',
								   duration: 2000
								});
							}
						}
					  },
					  fail: (err) => {
						// 请求失败的处理逻辑
						console.error(err);
					  }
					});
				},
				// 删除图片
				deletePic(event) {
					this[`fileList${event.name}`].splice(event.index, 1)
				},
				// 新增图片
				async afterRead(event) {
					// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
					let lists = [].concat(event.file)
					let fileListLen = this[`fileList${event.name}`].length
					lists.map((item) => {
						this[`fileList${event.name}`].push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.uploadFilePromise(lists[i].url)
						let item = this[`fileList${event.name}`][fileListLen]
						this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result
						}))
						fileListLen++
					}
				},
				uploadFilePromise(url) {
					return new Promise((resolve, reject) => {
						let a = uni.uploadFile({
							url: 'http://125.64.76.148:8125/KXJDDDApi/file/upload', // 仅为示例，非真实的接口地址
							filePath: url,
							name: 'file',
							formData: {
								user: 'test'
							},
							success: (res) => {
								setTimeout(() => {
									resolve(res.data.data)
								}, 1000)
							}
						});
					})
				},
		},
	}
</script>

<style>
.formBox{
	width: 98%;
	margin:-8rpx 10rpx 10rpx 9rpx ;
}
.labelBox{
	background-color: white;
	position: relative;
	top: 40rpx;
	display: flex;
	justify-content: space-between;
}
.labelBox2{
	background-color: white;
	position: relative;
	top: 70rpx;
	display: flex;
	justify-content: space-between;
}
.labelBox3{
	background-color: white;
	position: relative;
	top: 100rpx;
	display: flex;
	justify-content: space-between;
}
.djlyBox{
	line-height: 80rpx;
}
.djlyBox-text{
	margin-left: -420rpx;
}
.photoBox{
	/* width: 170rpx; */
	/* margin: 20rpx 0 0 280rpx; */
}
.btn{
	width: 200rpx;
	margin-top: 130rpx;
	margin-left:260rpx
}
</style>
